var path = require("path");
var express = require("express");
var cookieParser = require("cookie-parser");
var expressSession = require("express-session");
var passport = require("passport");
var connectEnsure = require("connect-ensure-login");
var app = express();
app.use(express.static("static"));
app.use(cookieParser())

app.use(expressSession({
    secret: "suijishuzi",
    resave: false,
    saveUninitialized: true,
    cookie: { maxAge: 60000 }
}))

app.use(passport.initialize());
app.use(passport.session());

var mongoose = require("mongoose");
mongoose.connect("127.0.0.1/blog");

var exphbs = require('express-handlebars');

app.set('views', path.join(__dirname, 'views'));

app.engine('.hbs', exphbs({
    layoutsDir: 'views/layouts',
    defaultLayout: 'main',
    extname: '.hbs',
}));
app.set('view engine', '.hbs');
var routerMain = require("./router/main");
var routerAuth = require("./router/auth");
var routerEditor = require("./router/editor");
var routerTravel = require("./router/travel");


app.use("/", routerMain);
app.use("/", routerAuth);
app.use("/", connectEnsure.ensureLoggedIn("/login"), routerEditor);
app.use("/", connectEnsure.ensureLoggedIn("/login"), routerTravel);

app.listen(9999);
console.log("开启服务器")